package com.mew.chess.core.game.pokdeng.game.message;

import com.mew.chess.core.game.pokdeng.game.PokDengSeatManager;
import com.zebra.common.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.ToString;

import java.util.List;

/**
 * @author dylin
 * @create 2021/5/7
 */
@Data
@ToString
public class CardMessage {
    private int seatNo;
    private List<Integer> cards;//牌
    private int cardType; //牌类型
    private int cardVal;  //牌大小
    private int cardRate; //牌倍数
    public void write(ByteBuf b) {
        ByteBufUtils.writeInt(b,seatNo);
        ByteBufUtils.writeInt(b,cards.size());
        for (Integer card : cards) {
            ByteBufUtils.writeInt(b,card);
        }
        ByteBufUtils.writeInt(b,cardType);
        ByteBufUtils.writeInt(b,cardVal);
        ByteBufUtils.writeInt(b,cardRate);
    }
    public static CardMessage buildByUser(PokDengSeatManager seat){
        CardMessage cm=new CardMessage();
        cm.setSeatNo(seat.getSeatNo());
        cm.setCards(seat.getUser().getCards());
        cm.setCardType(seat.getUser().getCardType());
        cm.setCardVal(seat.getUser().getCardVal());
        cm.setCardRate(seat.getUser().getCardRate());
        return cm;
    }
}
